package hlhj.fhp.checkpoint.atys

import android.support.v7.widget.LinearLayoutManager
import com.liaoinstan.springview.container.DefaultFooter
import com.liaoinstan.springview.container.DefaultHeader
import com.liaoinstan.springview.widget.SpringView
import hlhj.fhp.checkpoint.BaseAty
import hlhj.fhp.checkpoint.R
import hlhj.fhp.checkpoint.adp.MoneyAdp
import hlhj.fhp.checkpoint.iview.MoneyView
import hlhj.fhp.checkpoint.javaBean.MoneyBean
import hlhj.fhp.checkpoint.presenter.MoneyPresenter
import kotlinx.android.synthetic.main.lo_pub_head.*
import kotlinx.android.synthetic.main.lo_publist.*

/**
 * Created by Never Fear   on 2018\11\12 0012.
Never More....
 */
class MoneyAty :BaseAty<MoneyView,MoneyPresenter>(), MoneyView, SpringView.OnFreshListener {
    private val datas=ArrayList<MoneyBean.InfoBean.DataBean>()
    private var listAdp:MoneyAdp?=null
    private var page=1
    override fun initView() {
        tvTittle.setText("零钱明细")
        listAdp= MoneyAdp(datas)
        listView.adapter=listAdp
        listView.layoutManager=LinearLayoutManager(this,LinearLayoutManager.VERTICAL,false)
        spView.header=DefaultHeader(this)
        spView.footer=DefaultFooter(this)
    }

    override fun setMoney(moneyBean: MoneyBean) {
        if (page==1){
            datas.clear()
        }
        spView?.onFinishFreshAndLoad()
        datas.addAll(moneyBean.info.data)
        listAdp?.notifyDataSetChanged()
    }
    override fun onLoadmore() {
        page++
        presenter?.getMoney(this,page)
    }

    override fun onRefresh() {
        page=1
        presenter?.getMoney(this,page)

    }

    override fun logicStart() {
        presenter?.getMoney(this,page)
    }

    override fun setListener() {
        spView.setListener(this)
    }

    override fun bindView(): MoneyView {
        return this
    }

    override fun createPresenter(): MoneyPresenter {
        return MoneyPresenter()
    }

    override val contentId: Int= R.layout.aty_moeny_detail
}